home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / lanperf.arc / LANPERF.C next >
C/C++ Source or Header  |  1988-06-04  |  7KB  |  247 lines

  1. /*
  2.  *  LANPERF - PC Tech Journal LAN Performance Test
  3.  *  Copyright (c) 1988, Ziff Communications Company 
  4.  *
  5.  *  To build LANPERF.EXE:
  6.  *    cl /c LANPERF.C   (Compiled with Microsoft C 5.0)
  7.  *    masm LPTEST.ASM;  (Assembled with Microsoft MASM 4.0)
  8.  *    link LANPERF+LPTEST;
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. /* this value needs to match with the one in LPTEST.ASM */
  15. #define MAXBLK      4096    /* maximum blksize value */
  16.  
  17.  
  18. /* information used by rtest() and wtest() ASM routines */
  19.  
  20. int  master;                /* did we start the test? */
  21. unsigned int blksize;       /* block I/O size in bytes */
  22. unsigned int filesize;      /* size of file in blksize blocks */
  23. char ioshare;               /* sharing mode for tests */
  24. char iobuf[2*MAXBLK];       /* I/O buffer */
  25. unsigned int duration;      /* length of test (seconds) */
  26. long ops;                   /* total operations performed */
  27. char fname[20];             /* name of test file created */
  28.  
  29. char *modename[] =
  30.     {
  31.     "Compatibility", "Deny read/write", "Deny write",
  32.     "Deny read", "Deny none", "??"
  33.     };
  34.  
  35. main(int argc, char **argv)
  36. {
  37.     unsigned int atou(const char *str);
  38.     int i, err;
  39.     int do_read, do_write;
  40.  
  41.     printf("LANPERF Version 1.0\n");
  42.     printf("PC Tech Journal LAN Performance Test\n");
  43.     printf("Copyright (c) 1988, Ziff Communications Company\n\n");
  44.  
  45.     if ( argc < 2 )
  46.         {
  47.         printf("Options:\n");
  48.         printf(" t# - test length (seconds) (10-65535)\n");
  49.         printf(" b# - block size (in bytes) (1-%d)\n", MAXBLK);
  50.         printf(" f# - file size (in blocks) (1-65535)\n");
  51.         printf(" w  - do sequential write test\n");
  52.         printf(" r  - do sequential read test\n");
  53.         printf(" dM - file sharing mode\n");
  54.         printf("  ^ modes to deny (r w rw n c)\n");
  55.         printf(" x  - use defaults:  t60 b512 f64 r w dc\n");
  56.         exit(1);
  57.         }
  58.  
  59.     /* set default values */
  60.     blksize = 512;
  61.     filesize = 64;
  62.     duration = 60;
  63.     ioshare = 0;    /* compatibility mode */
  64.     do_read = 0;
  65.     do_write = 0;
  66.  
  67.     /* decode arguments */
  68.     for ( argv++, argc--; argc > 0; argv++, argc-- )
  69.         {
  70.         switch ( tolower(**argv) )
  71.             {
  72.             case 't' :
  73.                 duration = atou(*argv + 1);
  74.                 if ( duration < 10 )
  75.                     {
  76.                     printf("Illegal test time: %s\n", *argv);
  77.                     exit(1);
  78.                     }
  79.                 break;
  80.             case 'b':
  81.                 blksize = atou(*argv + 1);
  82.                 if ( blksize == 0 || blksize > MAXBLK )
  83.                     {
  84.                     printf("Illegal block size: %s\n", *argv);
  85.                     exit(1);
  86.                     }
  87.                 break;
  88.             case 'f':
  89.                 filesize = atou(*argv + 1);
  90.                 if ( filesize == 0 )
  91.                     {
  92.                     printf("Illegal file size: %s\n", *argv);
  93.                     exit(1);
  94.                     }
  95.                 break;
  96.             case 'd':
  97.                 switch ( tolower(*(*argv + 1)) )
  98.                     {
  99.                     case 'r':
  100.                         if ( tolower(*(*argv + 2)) == 'w' )
  101.                             ioshare = 0x10; /* deny r/w */
  102.                         else
  103.                             ioshare = 0x30; /* deny read */
  104.                         break;
  105.                     case 'w':
  106.                         ioshare = 0x20;     /* deny write */
  107.                         break;
  108.                     case 'n':
  109.                         ioshare = 0x40;     /* deny none */
  110.                         break;
  111.                     case 'c':
  112.                         ioshare = 0x00;     /* compatibility */
  113.                         break;
  114.                     default:
  115.                         printf("Illegal sharing mode: %s\n", *argv);
  116.                         exit(1);
  117.                     }
  118.                 break;
  119.             case 'w':
  120.                 do_write = 1;
  121.                 break;
  122.             case 'r':
  123.                 do_read = 1;
  124.                 break;
  125.             case 'x':
  126.                 break;
  127.             default:
  128.                 printf("unknown option: %s\n", *argv);
  129.                 exit(1);
  130.             }
  131.         }
  132.  
  133.     /* If read or write not specified, do both */
  134.     if ( !do_read && !do_write )
  135.         {
  136.         do_read = 1;
  137.         do_write = 1;
  138.         }
  139.  
  140.     printf("Test time  : %u seconds\n", duration);
  141.     printf("Block size : %u bytes\n", blksize);
  142.     printf("File size  : %u blocks (%lu bytes)\n",
  143.          filesize, (long)filesize * blksize);
  144.     printf("Sharing    : %s\n\n", modename[ioshare >> 4]);
  145.     printf("===> PRESS A KEY ON ANY STATION TO START <===\n\n");
  146.     printf("           Total     Mean Response  Throughput\n");
  147.     printf("Test     Operations    Time (ms)      (KB/s)\n");
  148.     printf("----     ----------  -------------  ----------\n");
  149.  
  150.     /* Fill buffer with random data pattern */
  151.     srand(19);
  152.     for ( i = 0; i < sizeof(iobuf); i++ )
  153.         iobuf[i] = rand();
  154.  
  155.     strcpy(fname, "LANPERF.GO");
  156.     unlink(fname);               /* in case it's already there */
  157.     if ( (err = lpstart()) )
  158.         fatal(err);
  159.  
  160.     if ( do_write )
  161.         {
  162.         printf("WRITE  :");
  163.         if ( (err = wtest()) )
  164.             fatal(err);
  165.         printf("%8ld      %8.3f      %8.2f\n",
  166.             ops,
  167.             1000.0 * (float)duration / (float)ops,
  168.             ((float)ops * (float)blksize) / (duration * 1024.0));
  169.         }
  170.  
  171.     if ( do_read )
  172.         {
  173.         printf("READ   :");
  174.         if ( (err = rtest()) )
  175.             fatal(err);
  176.         printf("%8ld      %8.3f      %8.2f\n",
  177.             ops,
  178.             1000.0 * (float)duration / (float)ops,
  179.             ((float)ops * (float)blksize) / (duration * 1024.0));
  180.         }
  181.  
  182.     if ( master )
  183.         unlink("LANPERF.GO");
  184.  
  185.     exit(0);
  186. }
  187.  
  188.  
  189. fatal(int err)
  190. {
  191. static char *doscode[] =
  192.     {
  193.     "No error",
  194.     "Invalid function",
  195.     "File not found",
  196.     "Path not found",
  197.     "Too many open files",
  198.     "Access denied",
  199.     "Invalid handle",
  200.     "Memory is trashed",
  201.     "Insufficient memory",
  202.     "Invalid memory block",
  203.     "Bad environment",
  204.     "Invalid format",
  205.     "Invalid access code",
  206.     "Invalid data",
  207.     "??",
  208.     "Invalid drive",
  209.     "Can't remove current directory",
  210.     "Not same device",
  211.     "No more matching files",
  212.     };
  213.     
  214.     if ( err < 0 )
  215.         printf("\nERROR: possible disk full?");
  216.     else
  217.         {
  218.         printf("\nDOS error %u, ", err);
  219.         if ( err >= sizeof(doscode)/sizeof(doscode[0]) )
  220.             printf("??\n");
  221.         else
  222.             printf("%s\n",doscode[err]);
  223.         }
  224.     unlink("LANPERF.GO");
  225.     exit(1);
  226. }
  227.  
  228. #include <ctype.h>
  229. #include <limits.h>
  230.  
  231. unsigned int
  232. atou(const char *str)
  233. {
  234.     unsigned long tmp = 0;
  235.  
  236.     /* convert a string to an unsigned integer */
  237.     while ( *str )
  238.         {
  239.         if ( isdigit(*str) )
  240.             tmp = tmp * 10 + (*str++ - '0');
  241.         else
  242.             return(0);      /* garbage */
  243.         }
  244.     if ( tmp > UINT_MAX )
  245.         return(0);          /* number too big */
  246.     return((unsigned int)tmp);
  247. }